mir: support more pixel formats
authorWilliam Hua <william.hua@canonical.com>
Tue, 13 Oct 2015 09:18:11 +0000 (10:18 +0100)
committerWilliam Hua <william.hua@canonical.com>
Wed, 14 Oct 2015 08:21:41 +0000 (09:21 +0100)
gdk/mir/gdkmirdisplay.c
gdk/mir/gdkmirwindowimpl.c

index 6eda3522c6efe50a4809051d824b9a7ba351adbe..73f8bcf8350dd78ac90a31e8f6c8bf878b88dc39 100644 (file)
@@ -539,12 +539,19 @@ get_pixel_formats (MirConnection *connection,
     {
       *sw_pixel_format = mir_pixel_format_invalid;
 
-      for (i = 0; i < n_formats; i++)
+      for (i = 0; i < n_formats && *sw_pixel_format == mir_pixel_format_invalid; i++)
         {
-          if (formats[i] == mir_pixel_format_argb_8888)
+          switch (formats[i])
             {
+            case mir_pixel_format_abgr_8888:
+            case mir_pixel_format_xbgr_8888:
+            case mir_pixel_format_argb_8888:
+            case mir_pixel_format_xrgb_8888:
+            case mir_pixel_format_rgb_565:
               *sw_pixel_format = formats[i];
               break;
+            default:
+              break;
             }
         }
     }
@@ -553,22 +560,20 @@ get_pixel_formats (MirConnection *connection,
     {
       *hw_pixel_format = mir_pixel_format_invalid;
 
-      for (i = 0; i < n_formats; i++)
+      for (i = 0; i < n_formats && *hw_pixel_format == mir_pixel_format_invalid; i++)
         {
           switch (formats[i])
-          {
+            {
             case mir_pixel_format_abgr_8888:
             case mir_pixel_format_xbgr_8888:
             case mir_pixel_format_argb_8888:
             case mir_pixel_format_xrgb_8888:
+            case mir_pixel_format_rgb_565:
               *hw_pixel_format = formats[i];
               break;
             default:
-              continue;
-          }
-
-          if (*hw_pixel_format != mir_pixel_format_invalid)
-            break;
+              break;
+            }
         }
     }
 }
index 9b3a249e54724145fb94b8b1c623a71d0b894eb3..05bec83d4ddc79af764c8c9d326fc0c9f3fbcc41 100644 (file)
@@ -423,7 +423,42 @@ gdk_mir_window_impl_ref_cairo_surface (GdkWindow *window)
       ensure_surface (window);
 
       mir_buffer_stream_get_graphics_region (mir_surface_get_buffer_stream (impl->surface), &region);
-      g_assert (region.pixel_format == mir_pixel_format_argb_8888);
+
+      switch (region.pixel_format)
+        {
+        case mir_pixel_format_abgr_8888:
+          g_warning ("pixel format ABGR 8888 not supported, using ARGB 8888");
+          pixel_format = CAIRO_FORMAT_ARGB32;
+          break;
+        case mir_pixel_format_xbgr_8888:
+          g_warning ("pixel format XBGR 8888 not supported, using XRGB 8888");
+          pixel_format = CAIRO_FORMAT_RGB24;
+          break;
+        case mir_pixel_format_argb_8888:
+          pixel_format = CAIRO_FORMAT_ARGB32;
+          break;
+        case mir_pixel_format_xrgb_8888:
+          pixel_format = CAIRO_FORMAT_RGB24;
+          break;
+        case mir_pixel_format_bgr_888:
+          g_error ("pixel format BGR 888 not supported");
+          break;
+        case mir_pixel_format_rgb_888:
+          g_error ("pixel format RGB 888 not supported");
+          break;
+        case mir_pixel_format_rgb_565:
+          pixel_format = CAIRO_FORMAT_RGB16_565;
+          break;
+        case mir_pixel_format_rgba_5551:
+          g_error ("pixel format RGBA 5551 not supported");
+          break;
+        case mir_pixel_format_rgba_4444:
+          g_error ("pixel format RGBA 4444 not supported");
+          break;
+        default:
+          g_error ("unknown pixel format");
+          break;
+        }
 
       cairo_surface = cairo_image_surface_create_for_data ((unsigned char *) region.vaddr,
                                                            pixel_format,